/*
 * @authors mail: eventosgasteiz@gmail.com
 * 		David Benito
 * 		Juan Lopez
 * 		Imanol Nieto
 * 		Araceli Alday
 * ----------------------------------------------------------------------
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version. 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
*/

package com.eventosgasteiz.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.google.android.maps.MapView;

/**
 * Vista asociada al mapa.
 */
public class LocationMapView extends MapView {

	private long lastTouchTime = -1;

	public LocationMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (ev.getAction() == MotionEvent.ACTION_DOWN) {
			long thisTime = System.currentTimeMillis();
			if (thisTime - lastTouchTime < 250) {
				// Double tap
				if (this.getZoomLevel()<=2){
					// Hacemos zoom
					this.getController().zoomInFixing((int) ev.getX(),
							(int) ev.getY());
				}
				/* Por ahora solo zoom en el doble click
				else {
					// Geolocalizamos
					GeoPoint p = this.getProjection().fromPixels(
		                    (int) ev.getX(),
		                    (int) ev.getY());
		                    
					((LocationMapActivity)getContext()).mapCurrentAddress(p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6);
				} */
				lastTouchTime = -1;
			} else {
				// Too slow :)
				lastTouchTime = thisTime;
			}
		}

		return super.onInterceptTouchEvent(ev);
	}

}
